using System;
using System.Drawing;
using System.Windows.Forms;
using Diagram.Model;
using Diagram.Tools;
using Diagram.View;

namespace PetriDiagram.Tools
{
    [Serializable]
    public class FireTransitionTool : Tool
    {
        public FireTransitionTool( EntityManager entityManager, Diagram.View.Diagram diagram )
            : base( entityManager, diagram )
        {
            Name = "Fire transition";
        }

        public override void OnMouseMove( Point location )
        {
            Shape shape = Diagram.FindShape( location );

            if( shape != null && shape.Entity is Transition )
            {
                Transition transition = shape.Entity as Transition;

                if( transition.IsActive )
                    Cursor.Current = Cursors.Hand;
                else
                    Cursor.Current = Cursors.No;
            }
            else
                Cursor.Current = Cursors.Cross;

            base.OnMouseMove( location );
        }

        public override void OnLMBDown( Point location )
        {
            Shape shape = Diagram.FindShape( location );

            if( shape !=null && shape.Entity is Transition )
            {
                Transition t = shape.Entity as Transition;

                if( t.IsActive )
                    t.Fire();
            }

            base.OnLMBDown( location );
        }
    }
}
